﻿Imports DevComponents.DotNetBar.SuperGrid
Imports DevComponents.DotNetBar.SuperGrid.Style

Public Class SOFTWARE
    Dim connect As CONDB = CONDB.NewConnection()
    Dim selectPrgRow As Integer = -1

    Public Sub querySoftwareGrid()
        Dim dt As DataTable = connect.GetTable("SELECT prgid as 'รหัสซอฟต์แวร์', prgcode as 'Code ซอฟต์แวร์', prgname as 'ชื่อซอฟต์แวร์', status as 'สถานะการเปิดใช้งาน' FROM masprg")
        softwareGrid.PrimaryGrid.DataSource = dt
    End Sub

    Private Sub SOFTWARE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        querySoftwareGrid()
    End Sub

    Private Sub softwareGrid_CellClick(sender As Object, e As GridCellClickEventArgs) Handles softwareGrid.CellClick
        If e.MouseEventArgs.Button = Windows.Forms.MouseButtons.Right Then
            selectPrgRow = e.GridCell.RowIndex
        End If
    End Sub

    Private Sub editNameOfSoftwareGroup_Click(sender As Object, e As EventArgs) Handles editNameOfSoftwareGroup.Click
        Dim prgid As String = CType(softwareGrid.PrimaryGrid.Rows(selectPrgRow), GridRow).Cells("รหัสซอฟต์แวร์").Value
        Dim prgCode As String = CType(softwareGrid.PrimaryGrid.Rows(selectPrgRow), GridRow).Cells("Code ซอฟต์แวร์").Value
        Dim prgName As String = CType(softwareGrid.PrimaryGrid.Rows(selectPrgRow), GridRow).Cells("ชื่อซอฟต์แวร์").Value
        Dim prgStatus As Integer = CType(softwareGrid.PrimaryGrid.Rows(selectPrgRow), GridRow).Cells("สถานะการเปิดใช้งาน").Value

        Dim CMSPHERE As New SOFTWAREEDIT(prgid, prgCode, prgName, prgStatus)
        Dim resultForm As DialogResult = CMSPHERE.ShowDialog

        If resultForm = Windows.Forms.DialogResult.OK Then
            querySoftwareGrid()
        End If
    End Sub

    Private Sub newSoftwareGroupBtn_Click(sender As Object, e As EventArgs) Handles newSoftwareGroupBtn.Click
        Dim newFOrm As New NEWSOFTWARE()
        Dim resultForm As DialogResult = newFOrm.ShowDialog()

        If resultForm = Windows.Forms.DialogResult.OK Then
            querySoftwareGrid()
        End If
    End Sub
End Class